﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Aspose.Slides.Pptx;
using Aspose.Slides.Export;

namespace PPTUtilities
{
    class Template
    {
        public static void AddTemplates(string templateName, string sourceName)
        {
            PresentationEx sourcePres = new PresentationEx(sourceName);

            //Template presentation
            PresentationEx templatePres = new PresentationEx(templateName);

            //Template slide
            SlideEx templateSlide = templatePres.Slides[0];

            //Get the template master from template slide
            MasterSlideEx templateMaster = templateSlide.LayoutSlide.MasterSlide;

            //Copy template master into source presentation
            int sourceMasterIndex = sourcePres.Masters.AddClone(templateMaster);

            //Access the compy of template master from source presentation
            MasterSlideEx sourceMaster = sourcePres.Masters[sourceMasterIndex];

            //Change master of all source slides
            sourcePres.Slides[0].LayoutSlide.MasterSlide = sourceMaster;
            //foreach (SlideEx slide in sourcePres.Slides)
            //{
            //    slide.LayoutSlide.MasterSlide = sourceMaster;
            //}
            //Write source presentation output on disk
            sourcePres.Write(sourceName);
        }
    }
}
